<template>
  <div class="home-recommond">
      <h2>达人歌单</h2>
      <div class="wrapper" ref="wrapper">
          <ul class="content" ref="content">
              <li v-for="(item, index) in listData" :key="index"
                  @click="selectItem(item)">
                  <div class="cover">
                      <van-image :src="item.cover" radius="1rem" />
                      <span>{{ item.listen_num | numFilter(1) }}万</span>
                  </div>
                  <span>{{ item.title }}</span>
              </li>
          </ul>
      </div>
  </div>
</template>

<script>
import { betterScrollHorizontal } from "../../common/betterScroll";
export default {
  data() {
      return {
          listData: [],
      };
  },
  created() {
      this.getSongListData()
  },
  methods: {
      //获取推荐歌单数据
      getSongListData() {
          this.$request('get', '/recommend/playlist/u')
              .then((res) => {
                  console.log(res)
                  if (res.result == 100) {
                      this.listData = res.data.list;
                  }
                  //异步数据的一些处理
                  betterScrollHorizontal(
                      this,
                      this.$refs.wrapper,
                      this.$refs.content,
                      this.listData.length,
                      10
                  );
              });
      },
      selectItem(item){
          const id = item.content_id;//获取歌单的id
          console.log(id);
          //1.本名的路由name，并加上参数，让路由建立url
          this.$router.push({
              path: `/songlist/${id}`
              // name:"songlist",
              // params:{
              //     id:id  //等同于id
              // }
          })
      },
  },
};
</script>

<style scoped>
.cover {
  position: relative;
}

.cover>span {
  position: absolute;
  right: 0.2rem;
  bottom: 0.4rem;
  background-color: #a6a0a0;
  color: white;
  font-size: 14px;
  border-radius: 1rem;
  width: 5rem;
  display: inline-block;
}

.wrapper {
  width: 100%;
  /*容器的宽度就是屏幕的宽度 */
  overflow: hidden;
}

ul.content li {
  /*li默认是块级元素，修改为行内元素，但是要具备块级元素的特性*/
  display: inline-block;
  width: 10rem;
  vertical-align: top;
  /*垂直方向的位置*/
}

/* li里面有两个元素：div和span，所以使用通配符* */
ul.content li * {
  margin: 0 0.1rem;
  /*里面的元素与li的边距有个间距*/
}

ul.content li>span {
  font-size: 0.8rem;
  color: #54493b;
}</style>
